package com.zzyk.main.mapper;


import com.zzyk.main.model.pojo.RolePermission;
import com.zzyk.main.model.pojo.SysPermission;
import com.zzyk.main.model.vo.PermissionNode;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

@Component
@Mapper
public interface SysPermissionDao {

    // 根据权限ID获取权限信息
    public SysPermission getPermissionById(@Param("permissionId") int permissionId);

    // 根据权限名称获取系统权限信息
    public SysPermission getPermissionByName(@Param("permissionName") String permissionName);

    // 获取系统权限列表(模糊查询)
    public List<SysPermission> getPermissionList(SysPermission sysPermission);

    // 添加系统角色的权限
    public int addRolePermission(@Param("rolePermissionList") List<RolePermission> rolePermissionList);

    // 删除系统角色的权限
    public int deleteRolePermission(RolePermission rolePermission);

    // 根据系统角色删除权限
    public int deleteRolePermissionByRoleId(@Param("roleId") int roleId);

    // 根据系统角色查询权限
    public Set<SysPermission> getPermissionSetByRoleId(@Param("roleId") int roleId);

    @Select("SELECT * FROM tb_sys_permission WHERE `parent_id` = '0'")
    @ResultMap("permissionNode")
    public PermissionNode getPermissionRoot();

    @Select("SELECT * FROM tb_sys_permission WHERE `parent_id` = #{parentId}")
    @ResultMap("permissionNode")
    public LinkedHashSet<PermissionNode> getPermissionNode(@Param("parentId") Integer parentId);
}
